package co.fitstart.entity.coach;

import java.beans.Transient;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.core.utils.DateFormatUtils;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import co.fitstart.entity.course.schedule.CourseSchedule;
import co.fitstart.entity.principal.Principal;

@Entity
@Table(name = "coach_signin_statistic")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class CoachSigninStatistic {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 教练 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private Principal principal;
    
    /** 月份 */
    private String month;
    
    /** 课时数 */
    private BigDecimal hour;

    /** 成单体验课课时数 */
    private BigDecimal experienceHour;

    /** 赠课课时数 */
    private BigDecimal giveHour;
    
    /**
     * 
     */
    public CoachSigninStatistic() {
        
    }
    
    /**
     * 
     * @param courseSchedule
     */
    public CoachSigninStatistic(CourseSchedule courseSchedule) {
        this.principal = courseSchedule.getCoach();
        this.month = DateFormatUtils.format(courseSchedule.getOccurDate(), "yyyy-MM");
        this.experienceHour = new BigDecimal(0);
        this.giveHour = new BigDecimal(0);
        this.hour = new BigDecimal(0);
//        this.hour = new BigDecimal(
//                 courseSchedule.getCourse().isExperience() ? 1.5 : 
//                     courseSchedule.getCourse().getId() == new Long(743) ? 2 : 
//                         courseSchedule.getCourse().getId() == new Long(744) ? 2 : 1);
//        if(courseSchedule .getCourse().isExperience()) {
//            this.experienceHour = new BigDecimal(1.5);
//            this.giveHour = new BigDecimal(0);
//        } else if(courseSchedule.getCourse().isGive()) {
//            this.giveHour = new BigDecimal(1);
//            this.experienceHour = new BigDecimal(0);
//        } else {
//            this.experienceHour = new BigDecimal(0);
//            this.giveHour = new BigDecimal(0);
//        }
    }
    
    /**
     * 1v1&年卡
     * @param hour
     * @return
     */
    public CoachSigninStatistic hour(double hour) {
        if(this.hour != null) {
            this.hour = this.hour.add(new BigDecimal(hour));
            return this;    
        } else {
            this.hour = new BigDecimal(0).add(new BigDecimal(hour));
            return this;    
        }
    }

    /**
     * 成单体验课
     * @param hour
     * @return
     */
    public CoachSigninStatistic experienceHour(double hour) {
        this.hour = this.hour.add(new BigDecimal(hour));
        this.experienceHour = this.experienceHour.add(new BigDecimal(hour));
        return this;
    }

    /**
     * 赠课
     * @param hour
     * @return
     */
    public CoachSigninStatistic giveHour(double hour) {
        this.hour = this.hour.add(new BigDecimal(hour));
        this.giveHour = this.giveHour.add(new BigDecimal(hour));
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public boolean isCurrentMonth() {
        return month.equals(DateFormatUtils.format(new Date(), "yyyy-MM"));
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the principal
     */
    public Principal getPrincipal() {
        return principal;
    }

    /**
     * @param principal the principal to set
     */
    public void setPrincipal(Principal principal) {
        this.principal = principal;
    }

    /**
     * @return the month
     */
    public String getMonth() {
        return month;
    }

    /**
     * @param month the month to set
     */
    public void setMonth(String month) {
        this.month = month;
    }

    /**
     * @return the hour
     */
    public BigDecimal getHour() {
        return hour;
    }

    /**
     * @param hour the hour to set
     */
    public void setHour(BigDecimal hour) {
        this.hour = hour;
    }

    /**
     * @return the experienceHour
     */
    public BigDecimal getExperienceHour() {
        return experienceHour;
    }

    /**
     * @param experienceHour the experienceHour to set
     */
    public void setExperienceHour(BigDecimal experienceHour) {
        this.experienceHour = experienceHour;
    }

    /**
     * @return the giveHour
     */
    public BigDecimal getGiveHour() {
        return giveHour;
    }

    /**
     * @param giveHour the giveHour to set
     */
    public void setGiveHour(BigDecimal giveHour) {
        this.giveHour = giveHour;
    }
}
